package com.example.testhotload;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CheckUpdateUtils {
    @SuppressWarnings("unused")
    public static void checkUpdate(String appCode,String curVersion,final CheckCallBack updateCallback){
        ApiService apiService = ServiceFactory.createServiceFrom(ApiService.class);
        apiService.getUpdateInfo().subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateAppInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        updateCallback.onError();
                    }

                    @Override
                    public void onNext(UpdateAppInfo updateAppInfo) {
                        if(updateAppInfo.error_code==0||updateAppInfo.data==null||updateAppInfo.data.updateurl==null){
                            updateCallback.onError();
                        }else{
                            updateCallback.onSuccess(updateAppInfo);
                        }
                    }
                });
    }
}
